<?php

namespace App\Http\Controllers\Api;

use App\logic\HealthLogic;
use Illuminate\Http\Request;

class HealthController extends BaseController
{
    /**
     * yuql
     * 科普列表 controller
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(){
        $result = HealthLogic::indexLogic();
        return $this->witejson(0,$result,'科普列表展示成功');
    }

    /**
     * yuql
     * 科普添加 controller
     * @param Request $request
     *
     */
    public function healthAdd(Request $request){
        try {
            $params = $request->post();
            $result = HealthLogic::healthAdd($params);
            return $this->witejson(0,$result,'科普添加成功');
        } catch (\Exception $exception){
            return $this->witejson(1,'',$exception->validator->errors()->first());
        }
    }

    /**
     * yuql
     * 科普详情 controller
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function healthDetail(Request $request){
        try {
            $id = $request->get('id');
            $result = HealthLogic::healthDetail($id);
            return $this->witejson(0,$result,'科普详情展示成功');
        } catch (\Exception $exception){
            return $this->witejson(1,'',$exception->getMessage());
        }
    }

    /**
     * yuql
     * 科普修改 controller
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function healthUpdate(Request $request){
        try {
            $params = $request->post();
            $result = HealthLogic::healthUpdate($params);
            return $this->witejson(0,$result,'科普修改成功');
        } catch (\Exception $exception){
            return $this->witejson(1,'',$exception->validator->errors()->first());
        }
    }

    /**
     * yuql
     * 科普删除 controller
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function healthDel(Request $request){
        try {
            $id = $request->get('id');
            $result = HealthLogic::healthDel($id);
            return $this->witejson(0,$result,'科普删除成功');
        } catch (\Exception $exception){
            return $this->witejson(1,'',$exception->getMessage());
        }
    }
}
